﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bullet : MonoBehaviour
{

    private float _bulletSpeed = 10;
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(transform.up * _bulletSpeed * Time.deltaTime, Space.World);
    }

    void Hurt()
    {

    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        switch (collision.gameObject.tag)
        {
            case "Enemy":
                if (gameObject.tag != collision.tag)
                {
                    collision.SendMessage("Hurt");
                    DestroyBullet();
                }
                break;
            case "MyTank":
                if (gameObject.tag != collision.tag)
                {
                    collision.SendMessage("Hurt");
                    DestroyBullet();
                }
                break;
            case "Wall":
                Destroy(collision.gameObject);
                DestroyBullet();
                break;
            case "Barrier":
                DestroyBullet();
                break;
            case "Heart":
                Game.Instance.GameOver();
                DestroyBullet();
                break;
            default:
                break;
        }
    }

    private void DestroyBullet(float time = 0)
    {
        Destroy(gameObject, time);
    }
}
